﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Configuration;

namespace CsharpTrainer.Linq.Service.Northwind
{
    public class CascadeTableService
    {
        public bool AddCascadeTables(CascadeA tableA, List<CascadeB> tablesB, List<CascadeC> tablesC)
        {
            bool result;
            
            try
            {
                using (DataContext context = new DataContext(ConfigurationManager.ConnectionStrings["NorthwindConnStr"].ToString()))
                {
                    using (NorthwindDBDataContext northwindContext = new NorthwindDBDataContext())
                    {
                        northwindContext.CascadeA.InsertOnSubmit(tableA);
                        northwindContext.CascadeB.InsertAllOnSubmit(tablesB);
                        northwindContext.CascadeC.InsertAllOnSubmit(tablesC);

                        northwindContext.SubmitChanges();
                    }

                }

                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                result = false;
            }

            return result;
        }
    }
}









